<?php


class AppController extends Controller {
var $filterConditions=array();
    var $components=array('RequestHandler','Auth','Session','Email','Gestdate','Sendmail','Validform','Excel');
    var $helpers=array('Html','Form','Session','Camelcase','Ajax','Excel');
    var $IsAjax=false;
    var $admin="";
    
//    var $allFunctions=array(
//            'home','login','logout','filterUsers','showUser','addUser', //user
//            'test','editNewUser','editNewCompany','editJob','editWorkflow', //dmdform
//            'editNewBackup','editNewManager','addUser','addBackup','addManager','addProfileReference',//dmdform
//            'addCompany','addPc','addTools','addNotesAndExecutionDate','saveData','newDmdform','saveDmdform',//dmdform
//            'updateDmdform',//dmdform
//            'filterCompanies', //company
//            'showForms','showDmdformDetails','getUserDetails','getCompanyDetails',//Formstatus
//            'getManagerDetails','getBackupDetails','showStatusChange','showFormStatus','filterForms',//formstatus
//            ' populateList',// powerdelegation
//            'countForms', //kpi
//            );
//    var $DemanderFunctions=array(
//            'home','login','logout','filterUsers','showUser', //user
//            'editNewUser','editNewCompany','editJob','editWorkflow', //dmdform
//            'editNewBackup','editNewManager','addUser','addBackup','addManager','addProfileReference',//dmdform
//            'addCompany','addPc','addTools','addNotesAndExecutionDate','saveData','newDmdform','saveDmdform',//dmdform
//            'updateDmdform',//dmdform
//            'filterCompanies', //company
//            'showForms','showDmdformDetails','getUserDetails','getCompanyDetails','filterForms',//Formstatus
//            'getManagerDetails','getBackupDetails','showStatusChange',//formstatus
//        ' populateList'// powerdelegation
//            );
//    var $ItFunctions=array(
//            'home','login','logout', //user
//            'filterCompanies', //company
//            'showForms','showDmdformDetails','getUserDetails','getCompanyDetails',//Formstatus
//            'getManagerDetails','getBackupDetails','showStatusChange','filterForms',//formstatus
//            );
//    var $RequesterFunctions=array(
//            'home','login','logout', //user
//            'countForms', //kpi
//            
//            );
//    
    var $basicUserArray=array(
        '_constructFilter','_createAction','_getStatusByGroup','account','beforeFilter','changePassword','filterForms','getBackupDetails','getBranchDetails','getCompanyDetails','getJobsDetails','getManagerDetails','getManagerValidationDetails','getPcDetails','getToolsDetails','getUserDetails','home','login','logout','showDmdformDetails','showForms',
        'changeLang','add'
    );
    var $demanderArray=array(
      '_constructFilter','_createAction','_createCode','_createDmdform','_createFormStatus','_getStatusByGroup','_validateBackup','_validateCompany','_validateJobs','_validateManager','_validateTool','_validateUser','account','addBackup','addCompany','addManager','addNotesAndExecutionDate','addPc','addProfileReference','addTools','addUser','beforeFilter','changePassword','checkCompatibility','editBranch','editJob','editNewBackup','editNewCompany','editNewManager','editNewUser','editUser','editUser','editWorkflow','filterCompanies','filterForms','filterUsers','findCompany','getBackupDetails','getBranchDetails','getCompaniesForCountry','getCompanyDetails','getCompanyId','getCountries','getDepartmentsForSite','getJobsDetails','getManagerDetails','getManagerValidationDetails','getPcDetails','getSitesForCompany','getToolsDetails','getUserDetails','home','joblist','listActions','login','logout','managerValidation','newDmdform','populateList','saveData','saveDmdform','showDmdformDetails','showForms','showStatusChange','showUser','updateDmdform','validateData'  
        ,'changeLang','add'
    );
    var $toolAdminArray=array(
        'showUser','showStatusChange','showForms','showDmdformDetails','populateList','logout','login','joblist','home','getUserDetails','getToolsDetails','getPcDetails','getManagerValidationDetails','getManagerDetails','getJobsDetails','getCompanyDetails','getBranchDetails','getBackupDetails','filterUsers','filterForms','filterCompanies','editUser','checkCompatibility','changePassword','beforeFilter','addUser','account','_getStatusByGroup','_createAction','_constructFilter'
        ,'changeLang','add'
    );
    var $eicoArray=array(
        'validateData','updateDmdform','test','showUser','showStatusChange','showKpis','showFormStatus','showForms','showDmdformDetails','saveDmdform','saveData','retest','prm07er','prm05kpiForCountry','prm05kpi','prm04kpi','prm01er','populateList','newDmdform','managerValidation','logout','login','listActions','joblist','home','getUserDetails','getToolsDetails','getSitesForCompany','getPcDetails','getManagerValidationDetails','getManagerDetails','getJobsDetails','getDepartmentsForSite','getCountries','getCompanyId','getCompanyDetails','getCompaniesForCountry','getBranchDetails','getBackupDetails','formPerType','findCompany','filterUsers','filterKpis','filterForms','filterCompanies','editWorkflow','editUser','editNewUser','editNewManager','editNewCompany','editNewBackup','editJob','editBranch','countForms','checkCompatibility','changePassword','beforeFilter','addUser','addTools','addProfileReference','addPc','addNotesAndExecutionDate','addManager','addCompany','addBackup','account','_validateUser','_validateTool','_validateManager','_validateJobs','_validateCompany','_validateBackup','_getStatusByGroup','_createFormStatus','_createDmdform','_createCode','_createAction','_countpermonth','_countFormsPerTypeInterval','_countFormsPerType','_constructFilter','changeLang'
		,'add'
    );
    var $requesterArray=array(
        'test','showKpis','showForms','showDmdformDetails','retest','prm07er','prm05kpiForCountry','prm05kpi','prm04kpi','prm01er','logout','login','home','getUserDetails','getToolsDetails','getPcDetails','getManagerValidationDetails','getManagerDetails','getJobsDetails','getCompanyDetails','getBranchDetails','getBackupDetails','formPerType','filterKpis','filterForms','countForms','changePassword','beforeFilter','account','_getStatusByGroup','_createAction','_countpermonth','_countFormsPerTypeInterval','_countFormsPerType','_constructFilter','changeLang'
		,'add'
    );

    function beforeFilter() {

        parent::beforeFilter();
        
        

        // Configuration de AuthComponent
        $this->Auth->userModel = 'User';
        $this->Auth->authorize='controller';
        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'home');
        $this->Auth->loginError = '<div class="headerUserInfoError">Login Error: check your login or password</div>';
        $this->Auth->authError = '<div class="headerUserInfoError">Access denied !</div>';
        
        
        
        switch ($this->Auth->user('group_id')){
                case 1:$this->Auth->allow('*');break;
                case 2:$this->Auth->deny('*');$this->Auth->allow('*');break;
                case 3:$this->Auth->deny('*');$this->Auth->allow($this->eicoArray);break;
                case 4:$this->Auth->deny('*');$this->Auth->allow($this->toolAdminArray);break;
                case 5:$this->Auth->deny('*');$this->Auth->allow($this->demanderArray);break;
                case 7:$this->Auth->deny('*');$this->Auth->allow($this->basicUserArray);break;
                case 6:$this->Auth->deny('*');$this->Auth->allow($this->requesterArray);break;
            }
            
            Configure::write('Config.language',  $this->Session->read('User.language'));
        //debug(Configure::read('Config.language'));

         
        if($this->RequestHandler->isAjax()){

            $this->layout='ajax';
            $this->IsAjax=true;
        }else{
            $this->IsAjax=false;
        }

        //debug($this->Session->read('chPwd'));
        if ($this->Session->read('chPwd')==1 && $this->params['action']!='changePassword' ){
           if($this->params['action']=='logout' ){
                $this->Session->write('chPwd',0);
           }else{
            $this->redirect(array('controller'=>'users','action'=>'changePassword'));
           }
        }
    }
    function changeLang($lang){
        
        $this->Session->write('User.language',$lang);
        //debug(Configure::read('Config.language'));
        $this->redirect($this->referer());
    }
    function isAuthorized()
      {
        
      }

}
?>